// 考虑时间复杂度, 尽量别嵌套循环, 否则算法时间复杂度总执行时间会是O(n)以上
function sumForTwoNumber(arr, target) {
    let storeSumRes = new Map()
    let result = []
    for (let i = 0; i < arr.length; i++) {
        let another = target - arr[i]
        let anotherIndex = storeSumRes.get(another)
        if (anotherIndex !== undefined) {
            result[0] = anotherIndex
            result[1] = i
            break
        } else {
            storeSumRes.set(arr[i], i)
        }
    }
    return result
}
const arr = [10, 5, 1, 2, 20]
console.log('两数之和结果 => ', sumForTwoNumber(arr, 6))